<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('是否处理')" prop="isHandel">
            <el-select v-model="form.isHandel" :placeholder="$t('是否处理')" @change="changeOptions">
              <el-option
                v-for="dict in yesNoOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-col :span="24">
            <el-form-item :label="$t('备注')" prop="remark">
              <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <SaveBtn has-permi="company:pcw" />
    </div>
  </div>
</template>

<script>
    import { savePcwRiskDetails, getPcwRiskDetails } from '@/api/company/pcw/pcwRiskDetails'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {},
                // 字典
                yesNoOptions: []
            }
        },
        created() {
          this.getDicts('sys_yes_no').then(response => {
            this.yesNoOptions = response.data
          })
        },
        methods: {
            // 初始化数据
            init(id) {
              this.loading = true
                if (id != null && id !== undefined) {
                    getPcwRiskDetails(id).then(response => {
                      if (response.data !== null && response.data !== undefined) {
                        this.form = response.data
                      } else {
                        this.form.id = id
                      }
                      this.loading = false
                    })
                } else {
                    this.reset()
                  this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                companyId: undefined,
                mainId: undefined,
                year: undefined,
                type: undefined,
                riskId: undefined,
                keyId: undefined,
                keyValue: undefined,
                isHandel: undefined,
                riskType: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                delFlag: undefined,
                remark: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.isHandelOpen = false
                // this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.isHandelOpen = false
                // 刷新list页面
                // this.$parent.$parent.getList()
            },
            changeOptions(v) {
              var obj = this.yesNoOptions.find(item => {
                return item.dictValue === v
              })
              this.form.isHandelLabel = obj.dictLabel
            },
            /** 提交按钮 */
            submitForm: function() {
              this.$refs['form'].validate(valid => {
                if (valid) {
                  this.loading = true
                  savePcwRiskDetails(this.form).then(response => {
                    if (response.code === 200) {
                      var row = {
                        isHandel: this.form.isHandel,
                        isHandelLabel: this.form.isHandelLabel
                      }
                      this.$parent.$parent.updateIsHandel(row)
                      this.msgSuccess(this.$t('保存成功'))
                      this.closeForm()
                    } else {
                      this.msgError(response.msg)
                    }
                    this.loading = false
                  }).catch(() => {
                    this.loading = false
                  })
                } else {
                  this.locationError(document)
                }
              })
           }

        }

    }
</script>
